package com.xyg.common.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToMany;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * 
 * @author Administrator
 *
 * @param <T>
 * @param <ID>
 */
@MappedSuperclass
@JsonAutoDetect(fieldVisibility = Visibility.NONE, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE, isGetterVisibility = Visibility.NONE, creatorVisibility = Visibility.NONE)
public abstract class TreeEntity<T,ID extends Serializable> extends DataEntity<T, ID> {
	
	/**父节点*/
	@ManyToOne(fetch = FetchType.LAZY,cascade={CascadeType.REFRESH,CascadeType.PERSIST,CascadeType.MERGE})
	protected T parent;
	
	/**名称*/
	protected String name;
	
	/***/
	@Column(name="st")
	protected Integer sort;
	
	@Column(name="lft")
	/**节点左值*/
	protected Integer left;
	
	@Column(name="rgt")
	/**节点右值*/
	protected Integer right;
	
	@OneToMany(mappedBy = "parent", fetch = FetchType.LAZY,cascade=CascadeType.REMOVE)
	protected List<T> childrens = new ArrayList<>();
	
	
	protected TreeEntity(){
		super();
	}
	
	protected TreeEntity(ID id) {
		super(id);
	}
	
	public T getParent() {
		return parent;
	}

	public void setParent(T parent) {
		this.parent = parent;
	}
	
	@JsonProperty
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getSort() {
		return sort;
	}

	public void setSort(Integer sort) {
		this.sort = sort;
	}

	/**
	 * @return the left
	 */
	public Integer getLeft() {
		return left;
	}

	/**
	 * @param left the left to set
	 */
	public void setLeft(Integer left) {
		this.left = left;
	}

	/**
	 * @return the right
	 */
	public Integer getRight() {
		return right;
	}

	/**
	 * @param right the right to set
	 */
	public void setRight(Integer right) {
		this.right = right;
	}

	/**
	 * @return the childrens
	 */
	public List<T> getChildrens() {
		return childrens;
	}

	/**
	 * @param childrens the childrens to set
	 */
	public void setChildrens(List<T> childrens) {
		this.childrens = childrens;
	}
	
	
}
